﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jzy.BLL.HR;
using Jzy.Core.Common.Web;
using Jzy.Core.Common;
using Jzy.Model.HR;
using System.Collections.Generic;
using Frame.Lib.Web;
using Frame.Lib.Common;
using Frame.Lib.Utilities;


public partial class HumanResource_Employee_List : PageList
{
  

    private EmployeeBO Employee
    {
        get
        {
            return EmployeeBO.Instance<EmployeeBO>();
        }
    }

    private string PageSize
    {
        get
        {
            return Request.QueryString["PageSize"];
        }
    }

    private string Condition
    {
        get
        {
            return Request.QueryString["Condition"];
        }
    }

    private string Status
    {
        get
        {
            return Request.QueryString["Status"];
        }
    }

   

    //private PagerSortSetting _setting;
    //private CustSort _sorter;

    protected void Page_Load(object sender, EventArgs e)
    {
        //_setting = this.Footer1.InitPager(new Jzy.Core.Common.Web.BindViewHandler(BindView));
        //_sorter = new CustSort(_setting, new BindViewHandler(BindView));
        //_sorter.Sort(btnIP, btnInputTime);

        if (!IsPostBack)
        {
            Pager.BindDrp(drpPager);

            List<EnumInfo> list = ConvertUtil.ConvertEnum(typeof(EmployeeStatus));
            list.Insert(0, new EnumInfo() { ID = 0, Name = "全部" });
            drpStatus.DataSource = list;
            drpStatus.DataTextField = "Name";
            drpStatus.DataValueField = "ID";
            drpStatus.DataBind();

            drpStatus.SelectedValue = ((int)EmployeeStatus.在职).ToString();


            if (!string.IsNullOrEmpty(this.PageSize))
            {
                drpPager.SelectedValue = this.PageSize;
            }
            if (!string.IsNullOrEmpty(this.Condition))
            {
                txtSearch.Text = this.Condition;
            }

            if (!string.IsNullOrEmpty(this.Status))
            {
                drpStatus.SelectedValue = this.Status;

            }

          
            BindView();
            
        }
        InitSelectID(hidSelectIDs);
        JSUtil.SetTableHeight("list", 145);
        AddAttr();
        
    }

    private void AddAttr()
    {
        JSUtil.DelConfirm(btnDelete, "用户");
        lnkAdd.HRef = "Edit.aspx";       
        JSUtil.ClickBtn(lnkDelete, btnDelete);
    }


    private void BindView()
    {
        LVUtil.Init(lv, lvHeader);
        chkSelectAll.Checked = false;       
        
        PagerSetting setting = new PagerSetting();
        setting.PageIndex = this.PageIndex;
        setting.PageSize = int.Parse(drpPager.SelectedValue);
        setting.OrderBy = "HireDate desc";

        if (drpStatus.SelectedValue != "0")
        {
            setting.Where = "Status = " + drpStatus.SelectedValue;
        }

        if (!string.IsNullOrEmpty(txtSearch.Text.Trim()))
        {
            if (!string.IsNullOrEmpty(setting.Where))
            {
                setting.Where += " and ";
            }
            setting.Where = "Name like @p0";
        }
        
        IEnumerable<EmployeeInfo> list = Employee.GetList(setting, txtSearch.Text.Trim());

        // setting.RecordCount = 80;
        lv.DataKeyNames = new string[] { "ID" };
        lv.DataSource = list;
        lv.DataBind();

        string prefix = GlobalVar.WebCurrPath + "List.aspx?PageSize=" + drpPager.SelectedValue + "&Status=" + drpStatus.SelectedValue + "&Condition=" + txtSearch.Text.Trim();


        litPager.Text = HtmlPager.Render(setting, prefix, true);

    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (strSelectIDs != "")
        {
            Employee.Delete(StrUtil.SplitToStr(strSelectIDs));
            BindView();
        }
    }
    protected void drpPager_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindView();
    }    

   

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindView();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        BindView();
    }

    protected void drpStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindView();
    }

    
}
